package com.minxi.java.Dao;

import java.sql.*;

public class base {
    static String url;
    static String userName;
    static String pwd;
    Connection connection = null;
    PreparedStatement preparedStatement=null;
    ResultSet resultSet=null;

    static {
        try {
                Class.forName("com.mysql.cj.jdbc.Driver");
                url = "jdbc:mysql://localhost:3306/airline?serverTimezone=Asia/Shanghai";
                userName = "root";
                pwd = "123456";
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
    }


    public void getconnection(){
        try {
            connection = DriverManager.getConnection(url, userName, pwd);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public ResultSet selectsql(String sql){
        getconnection();
        try {
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        closeconncetion();
        return resultSet;
    }

    public PreparedStatement updatasql(String sql){
        getconnection();
        try {
            preparedStatement = connection.prepareStatement(sql);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return preparedStatement;
    }





    public void closeconncetion(){
        try {
            connection.close();
            preparedStatement.close();
            resultSet.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


}
